import { doLogout } from "@/hooks/authorization"
import { useCommonMessage } from "@/utils"

export function handleAxiosError(code: number, data: any) {
    const { error } = useCommonMessage()
    switch (code) {
        case 400:
            error("请求失败！请您稍后重试")
            break
        case 401:
            error(data.message)
            doLogout(false)
            break
        case 403:
            error("当前账号无权限访问！")
            break
        case 404:
            error("你所访问的资源不存在！")
            break
        case 405:
            error("请求方式错误！请您稍后重试")
            break
        case 408:
            error("请求超时！请您稍后重试")
            break
        case 500:
            error("服务异常！")
            break
        case 502:
            error("网关错误！")
            break
        case 503:
            error("服务不可用！")
            break
        case 504:
            error("网关超时！")
            break
        default:
            error("请求失败！")
    }
}
